
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>this · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Landen">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-image-captions/image-captions.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="bind&call&apply.html" />
    
    
    <link rel="prev" href="对象的构建.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../01html/html简介.html">
            
                <a href="../01html/html简介.html">
            
                    
                    HTML
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../01html/01html.html">
            
                <a href="../01html/01html.html">
            
                    
                    a链接、图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../01html/02html.html">
            
                <a href="../01html/02html.html">
            
                    
                    列表、表格、表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../01html/h5新增.html">
            
                <a href="../01html/h5新增.html">
            
                    
                    h5新增
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../02css/css简介.html">
            
                <a href="../02css/css简介.html">
            
                    
                    CSS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../02css/居中、省略、清浮.html">
            
                <a href="../02css/居中、省略、清浮.html">
            
                    
                    居中、省略、清浮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../02css/浮动和定位.html">
            
                <a href="../02css/浮动和定位.html">
            
                    
                    浮动和定位
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../02css/变换、过渡、动画.html">
            
                <a href="../02css/变换、过渡、动画.html">
            
                    
                    变换、过渡、动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../02css/sass和rem.html">
            
                <a href="../02css/sass和rem.html">
            
                    
                    sass和rem
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../02css/flex、media、栅格化.html">
            
                <a href="../02css/flex、media、栅格化.html">
            
                    
                    flex、media、栅格化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="js简介.html">
            
                <a href="js简介.html">
            
                    
                    JavaScript
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="数据类型.html">
            
                <a href="数据类型.html">
            
                    
                    数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="字符串.html">
            
                <a href="字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="数组.html">
            
                <a href="数组.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="回流和重绘.html">
            
                <a href="回流和重绘.html">
            
                    
                    回流和重绘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="浏览器的渲染过程.html">
            
                <a href="浏览器的渲染过程.html">
            
                    
                    浏览器的渲染过程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="十大排序算法.html">
            
                <a href="十大排序算法.html">
            
                    
                    十大排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="对象的构建.html">
            
                <a href="对象的构建.html">
            
                    
                    对象的构建
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.8" data-path="this.html">
            
                <a href="this.html">
            
                    
                    this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="bind&call&apply.html">
            
                <a href="bind&call&apply.html">
            
                    
                    bind&call&apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="变量提升.html">
            
                <a href="变量提升.html">
            
                    
                    变量提升
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="作用域.html">
            
                <a href="作用域.html">
            
                    
                    作用域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.13" data-path="对象.html">
            
                <a href="对象.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.14" data-path="存储.html">
            
                <a href="存储.html">
            
                    
                    存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="事件.html">
            
                <a href="事件.html">
            
                    
                    事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="图片预览.html">
            
                <a href="图片预览.html">
            
                    
                    图片预览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.17" data-path="防抖节流.html">
            
                <a href="防抖节流.html">
            
                    
                    防抖节流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="同步异步.html">
            
                <a href="同步异步.html">
            
                    
                    同步异步
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.19" data-path="babel入门.html">
            
                <a href="babel入门.html">
            
                    
                    babel入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.20" data-path="nvm.html">
            
                <a href="nvm.html">
            
                    
                    nvm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.21" data-path="ES6.html">
            
                <a href="ES6.html">
            
                    
                    ES6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.22" data-path="ES6-ES11.html">
            
                <a href="ES6-ES11.html">
            
                    
                    ES6-ES11
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >this</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <h2 id="this">this</h2>
<p>&#x51FD;&#x6570;&#x6267;&#x884C;&#x65F6;&#x5173;&#x8054;&#x7684;&#x4E0A;&#x4E0B;&#x6587;</p>
<h2 id="&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65B9;&#x5F0F;&#x5BF9;-this-&#x6307;&#x5411;&#x7684;&#x5F71;&#x54CD;">&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65B9;&#x5F0F;&#x5BF9; this &#x6307;&#x5411;&#x7684;&#x5F71;&#x54CD;</h2>
<ol>
<li><p>&#x51FD;&#x6570;&#x8C03;&#x7528;</p>
</li>
<li><p>&#x975E;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;this&#x6307;&#x5411;window&#x5BF9;&#x8C61;</p>
</li>
<li>&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;this&#x6307;&#x5411;undefined</li>
</ol>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">say</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>); <span class="hljs-comment">// window</span>
}
say();
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">run</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-comment">// &#x5F00;&#x542F;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#xFF0C;&#x4F7F;&#x7528;&#x66F4;&#x52A0;&#x4E25;&#x683C;&#x7684;&#x8BED;&#x6CD5;&#x51C6;&#x5219;</span>
<span class="hljs-meta">    &apos;use strict&apos;</span>;
    <span class="hljs-comment">// abc = 10; // &#x62A5;&#x9519;&#xFF0C;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E2D;&#x4E0D;&#x5141;&#x8BB8;&#x64CD;&#x4F5C;&#x672A;&#x88AB;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>); <span class="hljs-comment">// undefined</span>
}
run();
</code></pre>
<ol>
<li><p>call,apply</p>
</li>
<li><p>&#x4F7F;&#x7528;call(thisArg),apply(thisArg)&#x65F6;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;(thisArg)&#x5C06;&#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;this</p>
</li>
</ol>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
}
<span class="hljs-keyword">let</span> std = {
    age: <span class="hljs-number">18</span>,
};
test.call(std);
</code></pre>
<ol>
<li><p>&#x6784;&#x9020;&#x51FD;&#x6570;&#x8C03;&#x7528;</p>
</li>
<li><p>&#x4F5C;&#x4E3A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x51FD;&#x6570;&#x5185;&#x90E8;this&#x6307;&#x5411;&#x4E8E;&#x6B63;&#x5728;&#x88AB;&#x521B;&#x5EFA;&#x7684;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;</p>
</li>
<li>&#x6CE8;&#x610F;&#xFF1A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x8FD4;&#x56DE;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x4E0D;&#x4F1A;&#x8986;&#x76D6;&#x539F;&#x672C;&#x7684;return this;&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x8FD4;&#x56DE;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x5219;&#x4F1A;&#x8986;&#x76D6;&#x539F;&#x672C;return&#x503C;(&#x53D6;&#x4EE3;&#x539F;&#x672C;this&#x7684;&#x8FD4;&#x56DE;)</li>
</ol>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Cat</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>); <span class="hljs-comment">// {}</span>
    <span class="hljs-keyword">this</span>.color = <span class="hljs-string">&quot;white&quot;</span>;
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>); <span class="hljs-comment">// {color:&quot;white&quot;}</span>
    <span class="hljs-comment">// &#x4E0B;&#x9762;&#x8FD4;&#x56DE;this&#x8FD9;&#x4E00;&#x6B65;&#x64CD;&#x4F5C;&#xFF0C;&#x7531;new&#x64CD;&#x4F5C;&#x7B26;&#x5E2E;&#x6211;&#x4EEC;&#x5B8C;&#x6210;</span>
    <span class="hljs-comment">// return this;</span>
}
<span class="hljs-keyword">let</span> cat1 = <span class="hljs-keyword">new</span> Cat();
<span class="hljs-built_in">console</span>.log(cat1);
</code></pre>
<ol>
<li><p>&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x8C03;&#x7528;</p>
</li>
<li><p>&#x4F5C;&#x4E3A;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x8C01;&#x8C03;&#x7528;&#xFF0C;this&#x6307;&#x5411;&#x4E8E;&#x8C01;</p>
</li>
</ol>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> people = {
    hobby: [<span class="hljs-string">&apos;&#x7BEE;&#x7403;&apos;</span>,<span class="hljs-string">&apos;&#x8DB3;&#x7403;&apos;</span>,<span class="hljs-string">&apos;&#x7FBD;&#x6BDB;&#x7403;&apos;</span>],
    sayHobby: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>); 
        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.hobby);
    }
};
people.sayHobby();
</code></pre>
<ol>
<li><p>&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x65F6;</p>
</li>
<li><p>&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5E76;&#x6CA1;&#x6709;&#x81EA;&#x8EAB;&#x7684;this,arguments</p>
</li>
<li>&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;this&#xFF0C;&#x6307;&#x5411;&#x4E8E;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x65F6;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#xFF1B;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> obj = {
    sayThis1: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
    },
    sayThis2: () =&gt; {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
    }
};
obj.sayThis1(); <span class="hljs-comment">// obj &#x5BF9;&#x8C61;</span>
obj.sayThis2(); <span class="hljs-comment">// window,&#x4E5F;&#x5C31;&#x662F;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x65F6;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;</span>
</code></pre>
<h2 id="&#x7BAD;&#x5934;&#x51FD;&#x6570;">&#x7BAD;&#x5934;&#x51FD;&#x6570;</h2>
<pre><code class="lang-js">btn.addEventListener(<span class="hljs-string">&quot;click&quot;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-comment">// &#x666E;&#x901A;function&#xFF0C;this&#x6307;&#x5411;&#x4E8E;&#x5F53;&#x524D;DOM&#x5BF9;&#x8C61;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x666E;&#x901A;&#x51FD;&#x6570; this:&quot;</span>,<span class="hljs-keyword">this</span>);
})
btn.addEventListener(<span class="hljs-string">&quot;click&quot;</span>,() =&gt; {
    <span class="hljs-comment">// &#x7BAD;&#x5934;&#x51FD;&#x6570;&#xFF0C;this&#x7531;&#x51FD;&#x6570;&#x5916;&#x90E8;&#x51B3;&#x5B9A;&#xFF1B;</span>
    <span class="hljs-comment">// &#x5F53;&#x524D;&#x4E8B;&#x4EF6;&#x4FA6;&#x542C;&#x662F;&#x5728;window&#x4E0B;&#x5B8C;&#x6210;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x7684;&#x5916;&#x90E8;&#x5BF9;&#x8C61;&#x5373;&#x4E3A;window&#xFF1B;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x7BAD;&#x5934;&#x51FD;&#x6570; this:&quot;</span>,<span class="hljs-keyword">this</span>);
})
</code></pre>
<ul>
<li><p>&#x4F7F;&#x7528;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x65F6;&#xFF1A;</p>
</li>
<li><p>&#x5F53;&#x5F62;&#x53C2;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x65F6;&#xFF0C;&#x5141;&#x8BB8;&#x4E0D;&#x7528; &#x5706;&#x62EC;&#x53F7; &#x5305;&#x88F9;</p>
</li>
<li>&#x7BAD;&#x5934;&#x53F3;&#x4FA7;&#x4E0D;&#x4F7F;&#x7528; {} &#x5305;&#x88F9;&#x65F6;&#xFF0C;&#x53F3;&#x4FA7;&#x8868;&#x8FBE;&#x5F0F;&#x9ED8;&#x8BA4;&#x4F5C;&#x4E3A; return &#x503C;</li>
</ul>

                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="对象的构建.html" class="navigation navigation-prev " aria-label="Previous page: 对象的构建">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="bind&call&apply.html" class="navigation navigation-next " aria-label="Next page: bind&call&apply">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"this","level":"1.4.8","depth":2,"next":{"title":"bind&call&apply","level":"1.4.9","depth":2,"path":"md/03js/bind&call&apply.md","ref":"./md/03js/bind&call&apply.md","articles":[]},"previous":{"title":"对象的构建","level":"1.4.7","depth":2,"path":"md/03js/对象的构建.md","ref":"./md/03js/对象的构建.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","toggle-chapters","image-captions","-anchor-navigation","-anchor-navigation-ex"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"image-captions":{"attributes":{"style":"left: 50%;position: relative;transform: translateX(-50%);"},"caption":"图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_","align":"center","variable_name":"_pictures"},"fontsettings":{"theme":"night","family":"sans","size":2},"toggle-chapters":{},"highlight":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Landen","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[]},"gitbook":"3.x.x"},"file":{"path":"md/03js/this.md","mtime":"2020-07-27T15:02:27.020Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-17T10:41:18.504Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

